package com.example.enterprisemanager.mvvm.fragment.allocate;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.enterprisemanager.BR;
import com.example.enterprisemanager.R;
import com.example.enterprisemanager.base.BaseMainFragment;
import com.example.enterprisemanager.base.BaseViewModel;
import com.example.enterprisemanager.databinding.FragmentAllocateBinding;
import com.example.enterprisemanager.mvvm.fragment.allocate.dialog.MyDialogAllocate;
import com.example.enterprisemanager.mvvm.fragment.allocate.dialog.OnDialogGetContext;

/**
 * A simple {@link Fragment} subclass.
 */
public class AllocateFragment extends BaseMainFragment<FragmentAllocateBinding, AllocateViewModel> {


    public static AllocateFragment newInstance() {
        return new AllocateFragment();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_allocate;
    }

    @Override
    protected Class<AllocateViewModel> getModelClass() {
        return AllocateViewModel.class;
    }

    @Override
    protected int getVariableId() {
        return BR.viewModel;
    }

    @Override
    protected void initView() {
        super.initView();
        mBinding.toolbar.setTitle(R.string.allocate);
        initToolbarNav(mBinding.toolbar, true);

        mBinding.rvAllocate.setLayoutManager(new LinearLayoutManager(_mActivity) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });
        mBinding.rvAllocate.setAdapter(mViewModel.adapter);

    }

    @Override
    protected void initData(@Nullable Bundle savedInstanceState) {
        mViewModel.sendEnrollMutableLiveData.observe(this, (sendEnroll) -> {
            new MyDialogAllocate().show("物资分配", new OnDialogGetContext() {
                @Override
                public void getEditContext(String num, String department) {
                    mViewModel.haveEnroll(Integer.parseInt(num),department,sendEnroll.getPosition(),sendEnroll.getEnrollGoods());
                }
            }, _mActivity.getSupportFragmentManager());
        });
    }

}
